var express = require('express');
var router = express.Router();

const {BarberModel,tzModel}=require('../../model/model');

router.post("/addtz",async(req,res)=>{
    await tzModel.create(req.body);
    res.send({code:200})
})
router.get("/gettz",async(req,res)=>{
    const list = await tzModel.find()
    res.send({list:list})
})
router.post("/addbarber",async(req,res)=>{
    await BarberModel.create(req.body);
    res.send({code:200})
})
router.get("/getbarber",async(req,res)=>{
    const {name} = req.query
    const list = await BarberModel.find({name})
    res.send({list:list[0]})
})
router.get("/gettype",async(req,res)=>{
    const {type} = req.query
    if (type == "全部") {
        list = await BarberModel.find()
    }else{
        list = await BarberModel.find({type:{$elemMatch:{$eq:type}}})
    }
    res.send({list})
})

router.get("/gettyper",async(req,res)=>{
    const {type,a,b} = req.query
    console.log(type,a,b);
    
    if(type == "全部"){
        list = await BarberModel.find({$and:[{gl:{$gte:a}},{gl:{$lte:b}}]})
    }else{
        list = await BarberModel.find({$and:[{type:{$elemMatch:{$eq:type}}},{gl:{$gte:a}},{gl:{$lte:b}}]})
    }
    res.send({list})
})
module.exports = router;